package com.cqut.li.common_util;


import java.io.*;

public class FileUtil {

    public synchronized static byte[] getBytesFromFile(String path) throws IOException {

        File file = new File(path);

        if (!file.exists()) {
            throw new FileNotFoundException(path);
        }

        try {
            System.out.println(path + " start");
            FileInputStream fileInputStream = new FileInputStream(file);
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(1024 * 2);
            byte[] b = new byte[1024 * 2];
            int n;
            int count = 0;
            while ((n = fileInputStream.read(b)) != -1) {
                byteArrayOutputStream.write(b, 0, n);
//                count += n;
//                System.err.println(Thread.currentThread() +"..." + count + " fileLength : " +file.length());
            }


            fileInputStream.close();
            byteArrayOutputStream.close();

            System.out.println(path + " end");
            return byteArrayOutputStream.toByteArray();

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("这是文件里转换");
        }
        return null;
    }



}
